package com.atguigu.ehcache;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import java.io.InputStream;

/**
 * className: TestEh
 * description:
 * date: 2024/6/18-12:26
 * <p>
 * project: shiro
 * package: com.atguigu.ehcache
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class TestEh {
    public static void main(String[] args) {
        // 获取编译目录下的资源的流对象
        InputStream input = TestEh.class.getClassLoader().getResourceAsStream("ehcache.xml");
        // 获取 EhCache 的缓存管理对象
        CacheManager cacheManager = new CacheManager(input);
        // 获取缓存对象
        Cache cache = cacheManager.getCache("HelloWorldCache");
        // 创建缓存数据
        Element element = new Element("name", "zhang3");
        // 存入缓存
        cache.put(element);
        // 从缓存中取出
        Element element1 = cache.get("name");
        System.out.println(element1.getObjectValue());
    }
}
